home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / STRDEL.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  1KB  |  79 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8. ;
  9. ; strdel- deletes characters from a string.
  10. ;
  11. ; inputs:
  12. ;
  13. ;    ES:DI- Points at the string to delete characters from.
  14. ;
  15. ;    CX-    Index into source string (ES:DI) to begin deletion.
  16. ;
  17. ;    AX-    Number of characters to delete.
  18. ;
  19. ;
  20. ;
  21.         public    sl_strdel
  22. ;
  23. ;
  24. sl_strdel    proc    far
  25.         or    ax, ax            ;Any chars to delete?
  26.         jnz    DoDelete
  27.         ret
  28. ;
  29. DoDelete:    push    es
  30.         push    di
  31.         push    si
  32.         push    ds
  33.         push    ax
  34.         push    bx
  35.         push    cx
  36.         mov    bx, ax            ;Save length
  37. ;
  38. ; First, search for the insertion point and make sure it doesn't occur
  39. ; beyond the end of the string:
  40. ;
  41.         mov    al, 0
  42.     repne    scasb
  43.         jz    DelDone            ;Quit if insertion after len.
  44.         mov    ax, es
  45.         mov    ds, ax
  46.         mov    si, di            ;Search for end of string.
  47.         mov    cx, bx
  48. SrchEOS:    lodsb
  49.         cmp    al, 0
  50.         jz    DelToEOS
  51.         loop    SrchEOS
  52. ;
  53. ; At this point, we've covered "BX" characters (bx holds # of chars to delete)
  54. ; so copy the rest of the string to the deletion point.
  55. ;
  56. CpyEOS:        lodsb
  57.         stosb
  58.         cmp    al, 0
  59.         jnz    CpyEOS
  60.         jmp    short DelDone
  61. ;
  62. ; Done here, we reached the end of the string before covering the # of chars
  63. ; to delete, so simply chop the string off at the deletion point.
  64. ;
  65. DelToEOS:    mov    byte ptr [di], 0
  66. DelDone:    pop    cx
  67.         pop    bx
  68.         pop    ax
  69.         pop    ds
  70.         pop    si
  71.         pop    di
  72.         pop    es
  73.         ret
  74. sl_strdel    endp
  75. ;
  76. ;
  77. stdlib        ends
  78.         end
  79.